{% extends "./inc/base.html" %}
{% block content %}
                <section class="vbox">
                    <header class="header bg-light dk">
                        <p>{{controller.meta_title}}</p>
                    </header>
                    <section class="scrollable wrapper">

                        <section class="panel panel-default">
                            <header class="panel-heading">
                                                                                                 提现列表
                                <i data-title="订单状态为已审核时才能确认，审核的订单才能进入执行中。" data-placement="bottom" data-toggle="tooltip" class="fa fa-info-sign text-muted" data-original-title="" title=""><i class="fa fa-question-circle"></i></i>
                            </header>
                            <div class="row wrapper">

                                <div class="col-sm-9 m-b-xs">
                                    <div class="btn-group">
                                        <a class="btn btn-sm btn-info {%if status == null %}active{%endif%}" href="/admin/finance/withdraw">全部订单</a>
                                        <a class="btn btn-sm btn-info {%if status == 0 %}active{%endif%}" href="/admin/finance/withdraw/?status=0">待审核</a>
                                        <a class="btn btn-sm btn-info {%if status == 1 %}active{%endif%}" href="/admin/finance/withdraw/?status=1">打款中</a>
                                        <a class="btn btn-sm btn-info {%if status == 2 %}active{%endif%}" href="/admin/finance/withdraw/?status=2">提现成功</a>
                                        <!-- 
                                        <a class="btn btn-sm btn-info " href="/admin/finance/withdraw/down2excel">导出EXCEL</a>
                                         -->
                                        <a class="btn btn-sm btn-info " href="#" id="down2excel">导出EXCEL</a>
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div class="input-group pull-right search-form">
                                        <input type="text" class="input-sm form-control" name="q" placeholder="编号|用户ID"
                                               value="{{controller.get('q')}}">
                                        <span class="input-group-btn">
                        <button class="btn btn-sm btn-default" type="button" id="search" url="/admin/finance/withdraw/{%if status %}?status={{status}}{% endif %}">搜索</button>
                      </span>
                                    </div>
                                </div>
                            </div>
                            <div class="table-responsive">
                                <table class="table table-hover b-t b-light">
                                    <thead>
                                    <tr>
                                        <th style="width:20px;"><label class="checkbox m-n i-checks"><input type="checkbox"><i></i></label></th>
                                        <th>编号</th>
                                        <th>申请时间</th>
                                        <th>申请金额</th>
                                        <th>会员账号</th>
                                        <th>提现信息</th>
                                        <!-- 
                                        <th>真实姓名</th>
                                        <th>银行卡号</th>
                                        <th>开户银行</th>
                                        <th>微信账号</th>
                                        <th>支付宝账号</th>
                                         -->
                                        <th>提现方式</th>
                                        <th>提现状态</th>
                                        <th>确认时间</th>
                                        <th>实际金额</th>
                                        <th>打款时间</th>
                                        <th>手续费</th>
                                        <th>操作</th>
                                        <!--  
                                        <th>打印</th>
                                        -->
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for item in list %}
                                    <tr >
                                        <td><label class="checkbox m-n i-checks"><input class="ids" type="checkbox" name="ids" value="{{item.id}}"><i></i></label></td>
                                        <td>{{item.withdraw_no}}</td>
                                        <td>{{item.create_time|moment("YYYY-MM-DD HH:mm")}}</td>
                                        <td>￥{{item.amount|formatCurrency}}</td>
                                        <td>{{item.user_id|get_nickname}}</td>
                                        <td>
                                        <div class="btn-group">
                                          {%if item.pay_code =='wx_withdraw' %}
                                          <p><a href="#"><i class="fa "></i>微信账号:{{item.wxno}}</a></p>
                                           {%elif item.pay_code == 'alipay_withdraw'%}
                                          <p><a href="#"><i class="fa "></i>支付宝账号:{{item.alipayno}}</a></p>
                                           {%elif item.pay_code == 'debit_withdraw' %}
                                           <p><a href="#"><i class="fa "></i>开户姓名:{{item.realname}}</a></p>
		                                   <p><a href="#"><i class="fa "></i>银行卡号:{{item.bankno}}</a></p>
		                                   <p><a href="#"><i class="fa "></i>开户银行:{{item.bankname}}</a></p>
                                           {%endif%}  
                                        </div>
                                        </td>
                                        <!-- 
                                        <td>{{item.realname}}</td>
                                        <td>{{item.bankno}}</td>
                                        <td>{{item.bankname}}</td>
                                        <td>{{item.wxno}}</td>
                                        <td>{{item.alipayno}}</td>
                                         -->
                                        <td>{{item.channel}}</td>
                                        <td class="text-danger">
                                           {%if item.status ==0 %}
                                           <span class="text-muted">待审核 </span>
                                           {%elif item.status ==1%}
                                           <span class="text-success">打款中</span>
                                           {%elif item.status == 2%}
                                           <span class="text-primary">提现成功</span>
                                           {%endif%}
                                        </td>
                                        <td>
                                        {%if item.accept_time %}{{item.accept_time|moment("YYYY-MM-DD HH:mm")}}{%else%}{%endif%}
                                        </td>
                                        <td>￥{{item.confirm_amount|formatCurrency}}</td>
                                        <td>
                                        {%if item.withdraw_time %}{{item.withdraw_time|moment("YYYY-MM-DD HH:mm")}}{%else%}{%endif%}
                                        </td>
                                        <td>￥{{item.handling_fee|formatCurrency}}</td>
                                        <td>
                                        <div class="btn-group">
		                                 <button data-toggle="dropdown" class="btn btn-default btn-xs dropdown-toggle"><i class="fa fa-cog"></i> 处理 <span class="caret"></span></button>
		                                  <ul class="dropdown-menu dropdown-menu-right">
		                                   <li><a href="/admin/finance/see/?id={{item.id}}" data-toggle="ajaxModal"><i class="fa fa-eye"></i> 查看</a></li>
		                                   <!-- 
		                                   {%if item.pay_status !=1 and item.status != 3 and item.delivery_status != 1 and item.status != 4%} 
		                                   <li><a href="/admin/order/edit/?id={{item.id}}" data-toggle="ajaxModal"><i class="fa fa-edit"></i> 编辑</a></li>
		                                   {%endif%}
                                           {%if item.status ==2 %} 
                                           <li><a href="/admin/order/audit/?id={{item.id}}" data-toggle="ajaxModal"><i class="fa fa-check-square-o"></i> 审核</a></li>
                                           {%elif item.status ==3 and item.delivery_status == 0%}
                                           <li><a href="/admin/order/ship/?id={{item.id}}" data-toggle="ajaxModal"><i class="fa fa-truck"></i> 发货</a></li>
                                           {%endif%}
                                           {%if item.status != 6 and item.delivery_status != 2 and item.status ==3%}
                                           <li><a href="/admin/order/finish/?id={{item.id}}" data-toggle="ajaxModal"><i class="fa fa-smile-o"></i> 完成</a></li>
                                           {%endif%}
                                           {%if item.status != 6%}
		                                   <li><a href="/admin/order/void/?id={{item.id}}" data-toggle="ajaxModal"><i class="fa fa-trash-o"></i> 作废</a></li>
                                           {%endif%}
                                           {%if item.status == 6%}
                                           <li><a href="/admin/order/del/?id={{item.id}}" class="confirm ajax-get"><i class="fa fa-trash-o"></i>删除</a></li>
                                           {%endif%}
                                            -->
                                           <li><a href="/admin/finance/remark/?id={{item.id}}" data-toggle="ajaxModal"><i class="fa fa-paperclip"></i> 备注</a></li>
		                                   </ul>
		                                  </div>
		                                </td>
		                                <!--  
                                        <td>
                                        <div class="btn-group dropleft">
		                  <button data-toggle="dropdown" class="btn btn-default btn-xs dropdown-toggle"><i class="fa fa-print"></i> 打印 <span class="caret"></span></button>
		                  <ul class="dropdown-menu dropdown-menu-right">
		                    <li><a href="#"><i class="fa fa-print"></i> 打印订单</a></li>
		                    
		                  </ul>
		                </div></td>
		                -->
                                    </tr>
                                    {% else %}
                                    <tr><td colspan="11"><div class="alert alert-warning alert-block">
                                        <button data-dismiss="alert" class="close" type="button">×</button>
                                        <p>This would display if the 'item' collection were empty</p>
                                    </div></td></tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                            <footer class="panel-footer">
                                <div class="row">


                                    <div class="col-sm-12 text-right text-center-xs">
                                        {{pagerData | safe}}
                                    </div>
                                </div>
                            </footer>
                        </section>
                    </section>
                </section>

{% endblock %}
{% block script%}
<script src="/static/admin/js/parsley/parsley.min.js"></script>
<script src="/static/admin/js/parsley/parsley.extend.js"></script>
<script>
    $(function () {
      //搜索功能
      $("#search").click(function(){
        var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
          url += '&' + query;
        }else{
          url += '?' + query;
        }
        window.location.href = url;
      });

      //回车自动提交
      $('.search-form').find('input').keyup(function(event){
        if(event.keyCode===13){
          $("#search").click();
        }
      });
      
      $("#down2excel").click(function(){
    	  var url =  '/admin/finance/down2excel/{%if status %}?status={{status}}{% endif %}';
    	  var query  = $('.search-form').find('input').serialize();
          query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
          query = query.replace(/^&/g,'');
          if( url.indexOf('?')>0 ){
            url += '&' + query;
          }else{
            url += '?' + query;
          }
          
          $.get(url,{},function(data){
        	  //alert(JSON.stringify(data));
                      if(data.errno == 0){
                          toastr.success("导出成功！");
                          tableToExcel(data.data);
                      }else{
                          toastr.error(data.errmsg);
                      }
                      //setTimeout(function(){ location.reload() }, 1100);
                  }
          );
		  
          
       });

    })
    
     function tableToExcel(jsonData){
      //要导出的json数据
      
      //列标题
      //开户姓名:张三   银行卡号:123456789987654321 开户银行:招商银行
      var str = '<tr><td>编号</td><td>申请时间</td><td>申请金额</td><td>会员账号</td><td>开户姓名</td><td>银行卡号</td><td>开户银行</td><td>支付宝账号</td><td>微信账号</td><td>提现方式</td><td>提现状态</td></tr>';
      //循环遍历，每行加入tr标签，每个单元格加td标签
      for(let i = 0 ; i < jsonData.length ; i++ ){
        str+='<tr>';
        for(let item in jsonData[i]){
            //增加\t为了不让表格显示科学计数法或者其他格式
            str+=`<td>${ jsonData[i][item] + '\t'}</td>`;     
        }
        str+='</tr>';
      }
      //Worksheet名
      var worksheet = 'Sheet1'
      var uri = 'data:application/vnd.ms-excel;base64,';
 
      //下载的表格模板数据
      var template = `<html xmlns:o="urn:schemas-microsoft-com:office:office" 
      xmlns:x="urn:schemas-microsoft-com:office:excel" 
      xmlns="http://www.w3.org/TR/REC-html40">
      <head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
        <x:Name>${worksheet}</x:Name>
        <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>
        </x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
        </head><body><table>${str}</table></body></html>`;
      //下载模板
      window.location.href = uri + base64(template);
      window.location.download ="提现记录.xsl";
    }
    //输出base64编码
    function base64 (s) { 
    	return window.btoa(unescape(encodeURIComponent(s))) 
    }

</script>
{% endblock%}